package com.nl.lib_project.view.dialog

import android.app.Activity
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.github.gzuliyujiang.dialog.ModalDialog
import com.nl.lib_core.tool.extends.dp2px
import com.nl.lib_core.tool.extends.loadImage
import com.nl.lib_project.R

/** 作者:LiBW 创建日期:2022/6/29 描述:艾尔兹海默第二题 点击弹窗 */
class AlzheimerQuestion2Dialog(activity: Activity, private val block: (Boolean?) -> Unit) :
    ModalDialog(activity) {
  init {
    setWidth(context.dp2px(320f))
    setHeight(context.dp2px(214f))
  }

  private var mHintTV: TextView? = null
  private var mImageView: ImageView? = null
  private var mAnswerRightIV: ImageView? = null
  private var mAnswerWrongIV: ImageView? = null
  private var currentSelect: Boolean? = null

  override fun createBodyView(): View {
    val view = View.inflate(context, R.layout.dialog_question_hint, null)
    mImageView = view.findViewById(R.id.mImageView)
    mHintTV = view.findViewById(R.id.mHintTV)
    mAnswerRightIV = view.findViewById(R.id.mAnswerRightIV)
    mAnswerWrongIV = view.findViewById(R.id.mAnswerWrongIV)
    return view
  }

  override fun createHeaderView(): View? {
    return View.inflate(activity, R.layout.dialog_header_style_4, null)
  }

  override fun onCancel() {}

  override fun onOk() {
    block(currentSelect)
  }

  override fun createFooterView(): View? {
    return null
  }

  override fun initView() {
    super.initView()
    mAnswerRightIV?.setOnClickListener {
      currentSelect = true
      mAnswerWrongIV?.setImageResource(R.drawable.answer_wrong_off)
      mAnswerRightIV?.setImageResource(R.drawable.answer_right_on)
    }
    mAnswerWrongIV?.setOnClickListener {
      currentSelect = false
      mAnswerWrongIV?.setImageResource(R.drawable.answer_wrong_on)
      mAnswerRightIV?.setImageResource(R.drawable.answer_right_off)
    }
  }

  /** 设置提示语 */
  fun setHint(str: String) {
    mHintTV?.text = str
  }

  /** 设置图片 资源文件 */
  fun setImage(resource: Int) {
    mImageView?.loadImage(activity, resource)
  }

  /** 设置图片 网络 */
  fun setImage(url: String) {
    mImageView?.loadImage(activity, url)
  }

  /** 设置按钮 是否回答正确 */
  fun setBtnFlag(right: Boolean) {
    if (right) mAnswerRightIV?.performClick() else mAnswerWrongIV?.performClick()
  }
}
